package damngoodcoffee.smart.commands;

import java.util.logging.Logger;

import com.google.inject.Inject;
import com.thoughtworks.selenium.CommandProcessor;

public class SeleniumCommand implements Command {
    private CommandProcessor commandProcessor;
    private static Logger logger = Logger.getLogger(SeleniumCommand.class
	    .getCanonicalName());

    @Inject
    public SeleniumCommand(CommandProcessor commandProcessor) {
	this.commandProcessor = commandProcessor;
    }

    @Override
    public int hashCode() {
	final int prime = 31;
	int result = 1;
	result = prime * result + ((command == null) ? 0 : command.hashCode());
	result = prime * result + ((target == null) ? 0 : target.hashCode());
	result = prime * result + ((value == null) ? 0 : value.hashCode());
	return result;
    }

    @Override
    public boolean equals(Object obj) {
	if (this == obj)
	    return true;
	if (obj == null)
	    return false;
	if (getClass() != obj.getClass())
	    return false;
	SeleniumCommand other = (SeleniumCommand) obj;
	if (command == null) {
	    if (other.command != null)
		return false;
	} else if (!command.equals(other.command))
	    return false;
	if (target == null) {
	    if (other.target != null)
		return false;
	} else if (!target.equals(other.target))
	    return false;
	if (value == null) {
	    if (other.value != null)
		return false;
	} else if (!value.equals(other.value))
	    return false;
	return true;
    }

    private String command;
    private String target;
    private String value;

    public void setTarget(String target) {
	this.target = target;
    }

    public void setValue(String value) {
	this.value = value;
    }

    public String getCommand() {
	return command;
    }

    public String getTarget() {
	return target;
    }

    public String getValue() {
	return value;
    }

    public void execute() {
	logger.info("Executing " + this.toString());
	commandProcessor.doCommand(command, new String[] { target, value });
    }

    public void setCommand(String command) {
	this.command = command;
    }

    public String toString() {
	return command + "|" + target + "|" + value;
    }
}
